import {UserModel} from '../../../models/user.js'

//获取应用实例
const app = getApp()
const userModel = new UserModel()

Page({
  data: {
    userIndex: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
  },
  //事件处理函数
  bindViewTap: function() {
    if (app.globalData.userInfo){
      wx.navigateTo({
        url: '../center/index'
      })
    }else {
      app.checkLoginStatus()
    }
  },
  bindToHome: function() {
    if (app.globalData.userInfo){
      wx.navigateTo({
        url: '../home/index'
      })
    }else {
      app.checkLoginStatus()
    }
  },
  bindToWorks: function() {
    if (app.globalData.userInfo){
      wx.navigateTo({
        url: '../works/index'
      })
    }else {
      app.checkLoginStatus()
    }
  },
  bindToFollow: function() {
    if (app.globalData.userInfo){
      wx.navigateTo({
        url: '../follow/index'
      })
    }else {
      app.checkLoginStatus()
    }
  },
  bindToFans: function() {
    if (app.globalData.userInfo){
      wx.navigateTo({
        url: '../fans/index'
      })
    }else {
      app.checkLoginStatus()
    }
  },
  bindToCollect: function() {
    if (app.globalData.userInfo){
      wx.navigateTo({
        url: '../collect/index'
      })
    }else {
      app.checkLoginStatus()
    }
  },
  bindToShoot: function() {
    if (app.globalData.userInfo){
      wx.navigateTo({
        url: '../shoot/index'
      })
    }else {
      app.checkLoginStatus()
    }
  },
  bindToOpinion: function() {
    if (app.globalData.userInfo){
      wx.navigateTo({
        url: '../opinion/index'
      })
    }else {
      app.checkLoginStatus()
    }
  },
  bindToAboutsWe: function() {
    wx.navigateTo({
      url: '../abouts_we/index'
    })
  },
  onLoad: function () {
    app.checkLoginStatus()
  },
  onShow: function () {
    console.log(app.globalData.userInfo)
    if (app.globalData.userInfo) {
      this._init(0)
    }
  },
  _init:function(id) {
    wx.showLoading({
      title: '正在加载中...',
    })
    userModel.getUserIndex(id).then(res=>{
      this.setData({
        userIndex: res.data,
        hasUserInfo: true
      })
      wx.hideLoading()
    })
  }


})
